# Contributor: Díaz Urbaneja Diego <sodomon2@gmail.com>
# Maintainer: Díaz Urbaneja Diego <sodomon2@gmail.com>
pkgname=lua-luastatic
_pkgname=luastatic
pkgver=0.0.12
pkgrel=1
pkgdesc="Build a standalone executable from a Lua program."
url="https://github.com/ers35/luastatic"
arch="all"
license="CC0-1.0"
options="!check" # make check not implemented
source="$pkgname-$pkgver.tar.gz::https://github.com/ers35/luastatic/archive/$pkgver.tar.gz"
builddir="$srcdir/$_pkgname-$pkgver"

_luaversions="5.1 5.2 5.3 5.4"
for _v in $_luaversions; do
	makedepends="$makedepends lua$_v-dev"
	subpackages="$subpackages lua$_v-${pkgname#lua-}:_package"
done

prepare() {
	default_prepare

	local lver; for lver in $_luaversions; do
		cp -r "$builddir" "$builddir-$lver"
	done
}

build() {
	local lver; for lver in $_luaversions; do
	msg "Building for Lua $lver..."
	cd "$builddir-$lver"
	if [ "$lver" = "5.1" ]; then
		make LUA=lua LIBLUA_A=/usr/lib/liblua.a
	else
		make LUA=lua$lver LUA_INCLUDE=/usr/include/lua$lver LIBLUA_A=/usr/lib/liblua-$lver.so.0
	fi
	done
}

package() {
	mkdir -p "$pkgdir"
}

_package() {
	local lver="${subpkgname:3:3}"
	pkgdesc="$pkgdesc $lver"
	depends="lua$lver"

	cd "$builddir-$lver"
	mkdir -p "$subpkgdir"/usr/bin/
	cp -a $_pkgname "$subpkgdir"/usr/bin/luastatic-$lver
	if [ $lver = 5.4 ]; then
		ln -sf /usr/bin/luastatic-$lver "$subpkgdir"/usr/bin/luastatic
	fi
}

sha512sums="83bdf50536eb9f817c394d309a56a1476b3d40262ab9e1a81b185f2d599ebfe523ebbf8559837a710b679941908aea1dc5bfd6e9aba6420b8cc41273d8a1b731  lua-luastatic-0.0.12.tar.gz"
